export default {
  state: {
    // 获取cookie中设置的语言，默认中文
    language: sessionStorage.getItem('language') || 'zh',
    // 获取cookie中设置的元素大小，默认最小
    size: sessionStorage.getItem('size') || 'mini',
    // 侧栏是否收起
    sidebar: { opended: !+sessionStorage.getItem('sidebarStatus') },
    // 导航条类型 default/inverse
    navbarLayoutType: { default: !+sessionStorage.getItem('navbarLayoutType') },
    // 侧栏皮肤 light/dark
    sidebarLayoutSkin: { dark: !+sessionStorage.getItem('sidebarLayoutSkin') }
    // bread
  },
  mutations: {
    // 设置语言
    SET_LANGUAGE: (state, language) => {
      state.language = language
      sessionStorage.setItem('language', language)
    },
    // 设置大小
    SET_SIZE: (state, size) => {
      state.size = size
      sessionStorage.setItem('size', size)
    },
    // 设置侧栏状态反转
    TOGGLE_SIDEBAR: (state) => {
      if (state.sidebar.opended) {
        sessionStorage.setItem('sidebarStatus', 1)
      } else {
        sessionStorage.setItem('sidebarStatus', 0)
      }
      state.sidebar.opended = !state.sidebar.opended
    },
    // 设置侧栏关闭
    CLOSE_SIDEBAR: (state) => {
      sessionStorage.setItem('sidebarStatus', 1)
      state.sidebar.opended = false
    },
    // 设置导航条类型
    SET_NAVLAYOUTTYPE: (state) => {
      if (state.navbarLayoutType.default) {
        sessionStorage.setItem('navbarLayoutType', 1)
      } else {
        sessionStorage.setItem('navbarLayoutType', 0)
      }
      state.navbarLayoutType.default = !state.navbarLayoutType.default
    },
    // 设置侧栏皮肤
    SET_SIDESKIN: (state) => {
      if (state.sidebarLayoutSkin.dark) {
        sessionStorage.setItem('sidebarLayoutSkin', 1)
      } else {
        sessionStorage.setItem('sidebarLayoutSkin', 0)
      }
      state.sidebarLayoutSkin.dark = !state.sidebarLayoutSkin.dark
    }
  },
  actions: {
    // 执行设置语言
    setLanguage ({ commit }, language) {
      commit('SET_LANGUAGE', language)
    },
    // 执行设置大小
    setSize ({ commit }, size) {
      commit('SET_SIZE', size)
    },
    // 侧栏状态反转
    toggleSideBar ({ commit }) {
      commit('TOGGLE_SIDEBAR')
    },
    // 关闭侧栏
    closeSidebar ({ commit }) {
      commit('CLOSE_SIDEBAR')
    },
    // 设置导航条类型
    toggleNavbar ({ commit }) {
      commit('SET_NAVLAYOUTTYPE')
    },
    // 设置侧栏颜色
    toggleSidebarSkin ({ commit }) {
      commit('SET_SIDESKIN')
    }
  }
}
